
(function(){
    let url = location.href
    console.log(url);
    let urlObj = getQueryString(url)
    console.log(urlObj);

    fetch('http://chst.vip:1234/api/getcategorybyid?categoryid=' + urlObj.categoryid)
    .then(response => {
        return response.json()
    }).then(res => {
        let data = res.result[0]
        console.log(data);
        // 获取导航分类
        $('#subNav .left a').eq(1).html(data.category + '>').attr('href','bijia.html?categoryid='+ urlObj.categoryid)
    })


    // 渲染 商品详情
    fetch('http://chst.vip:1234/api/getproduct?productid=' + urlObj.productid)
    .then(function(response){
        return response.json()
    }).then(function(res){
        let data = res.result[0]
        console.log(data);
        console.log(data.productName);
        console.log($('#subNav span'));
        $('#subNav span').eq(2).html(data.productName + '>')

        let ele = `
        <div class="info">
        <div class="img">
            ${data.productImg}
        </div>
        <div class="title">
            ${data.productName}
        </div>
        <div class="count">
            <div class="row">
                <div class="col">
                    <span>当前最低</span>
                    <span>￥6000</span>
                </div>
                <div class="col">
                    <span>优选评论</span>
                    <span>831143条</span>
                </div>
            </div>
        </div>
        <div class="makeprice">
                ${data.bjShop}
            </div>
            <div class="comment">
                <h4>网友评价</h4>
                <div class="contents">
                    
                </div>
            </div>
        `
        $('.main').html(ele);
    })

    // 渲染评论
    setTimeout(() => {
        fetch('http://chst.vip:1234/api/getproductcom?productid=' + urlObj.productid)
        .then(response => {
            return response.json()
        }).then(res => {
            let data = res.result
            console.log(data);
            let ele=''
            data.forEach(item => {
                ele += `
                <div class="content">
                <div class="up">
                    <span id="id">${item.comName}</span>
                    <span class="time">${item.comTime}</span>
                </div>
                <div class="content_in">
                    ${item.comContent}
                </div>
                <div class="from">
                    <span>${item.comFrom}</span>
                </div>
                </div>

                `
            });
            $('.contents').html(ele)
        })

    }, 20);


})();